<template>
	<scroll-view scroll-y="true" class="content">
		<!-- 预约弹窗 -->
		<view class="login_from_input">
			<view class="form-left">园区名称<span>*</span></view>
			<view class="login_from_fun"><input type="text" v-model="formData.nameofPark" placeholder="请输入园区名称"></view>
		</view>
		<view class="login_from_input">
			<view class="form-left">园区类型<span>*</span></view>
			<view class="login_from_fun"><input type="text" v-model="formData.parkType" placeholder="请输入园区类型"></view>
		</view>
		<view class="login_from_input">
			<view class="form-left">主导产业<span>*</span></view>
			<view class="login_from_fun"><input type="text" v-model="formData.primeMoverIndustry" placeholder="请输入主导产业"></view>
		</view>
		<view class="login_from_input">
			<view class="form-left">所属区域</view>
			<view class="login_from_fun">
				<picker style="width: 100%;" @change="areaChange" :value="areaIndex" :range-key="'name'"
					:range="areaArray">
					<view style="font-size: 28rpx; float:left;" class="uni-input">
						{{areaArray[areaIndex].name || '请选择所属区域'}}
					</view>
				</picker>
			</view>
		</view>
		<view class="login_from_input">
			<view class="form-left">已流转资金(万元)</view>
			<view class="login_from_fun"><input type="text" v-model="formData.alreadyCirculation" placeholder="请输入已流转资金"></view>
		</view>
		<view class="login_from_input">
			<view class="form-left">已投入资金(万元)<span>*</span></view>
			<view class="login_from_fun"><input type="text" v-model="formData.inputCondition" placeholder="请输入已投入资金"></view>
		</view>
		<view class="login_from_input">
			<view class="form-left">金融服务<span>*</span></view>
			<view class="login_from_fun"><input type="text" v-model="formData.financialService" placeholder="请输入金融服务"></view>
		</view>
		<view class="login_from_input">
			<view class="form-left">投入情况<span>*</span></view>
			<view class="login_from_fun"><input type="text" v-model="formData.hasinvestedSituation" placeholder="请输入投入情况"></view>
		</view>
		<view class="login_from_input">
			<view class="form-left">园区规模(㎡)<span>*</span></view>
			<view class="login_from_fun"><input type="text" v-model="formData.parkScale" placeholder="请输入园区规模"></view>
		</view>
		<view class="login_from_input">
			<view class="form-left">园区现有规模(㎡)</view>
			<view class="login_from_fun"><input type="text" v-model="formData.parkexistingScale" placeholder="请输入现有规模"></view>
		</view>
		<view class="login_from_input">
			<view class="form-left">营销现状<span>*</span></view>
			<view class="login_from_fun"><input type="text" v-model="formData.marketingSituation" placeholder="请输入营销现状"></view>
		</view>
		<view class="login_from_input">
			<view class="form-left">基本条件<span>*</span></view>
			<view class="login_from_fun"><input type="text" v-model="formData.basicCondition" placeholder="基本条件"></view>
		</view>
		<view class="login_from_input">
			<view class="form-left">城市定位<span>*</span></view>
			<view class="login_from_fun"><input type="text" v-model="formData.cityLocation" placeholder="请输入城市定位"></view>
		</view>
		<view class="login_from_input">
			<view class="form-left">园区效益<span>*</span></view>
			<view class="login_from_fun">
				<!-- <input type="text" style="height: 400rpx;  white-space:normal; word-break:break-all; word-warp:break-word;" v-model="formData.description" placeholder="请输入需求描述"> -->
				<textarea v-model="formData.parkbenefitCircumstance" placeholder="请输入园区效益"></textarea>
			</view>
		</view>
		<view class="login_from_input">
			<view class="form-left">地址<span>*</span></view>
			<view class="login_from_fun">
				<!-- <input type="text" style="height: 400rpx;  white-space:normal; word-break:break-all; word-warp:break-word;" v-model="formData.description" placeholder="请输入需求描述"> -->
				<textarea v-model="formData.address" placeholder="请输入地址"></textarea>
			</view>
		</view>
		<view class="login_from_input">
			<view class="form-left">推广情况</view>
			<view class="login_from_fun">
				<!-- <input type="text" style="height: 400rpx;  white-space:normal; word-break:break-all; word-warp:break-word;" v-model="formData.description" placeholder="请输入需求描述"> -->
				<textarea v-model="formData.extension" placeholder="请输入推广情况"></textarea>
			</view>
		</view>
		<view class="login_from_input">
			<view class="form-left">效益</view>
			<view class="login_from_fun">
				<!-- <input type="text" style="height: 400rpx;  white-space:normal; word-break:break-all; word-warp:break-word;" v-model="formData.description" placeholder="请输入需求描述"> -->
				<textarea v-model="formData.benefit" placeholder="请输入效益"></textarea>
			</view>
		</view>
		<view class="login_from_input">
			<view class="form-left">简介</view>
			<view class="login_from_fun">
				<!-- <input type="text" style="height: 400rpx;  white-space:normal; word-break:break-all; word-warp:break-word;" v-model="formData.description" placeholder="请输入需求描述"> -->
				<textarea v-model="formData.synopsis" placeholder="请输入简介"></textarea>
			</view>
		</view>
		<view class="login_from_input">
			<view class="form-left">平台介绍</view>
			<view class="login_from_fun">
				<!-- <input type="text" style="height: 400rpx;  white-space:normal; word-break:break-all; word-warp:break-word;" v-model="formData.description" placeholder="请输入需求描述"> -->
				<textarea v-model="formData.platformIntroduction" placeholder="请输入平台介绍"></textarea>
			</view>
		</view>
		<view class="login_from_input">
			<view class="form-left">人才队伍</view>
			<view class="login_from_fun">
				<!-- <input type="text" style="height: 400rpx;  white-space:normal; word-break:break-all; word-warp:break-word;" v-model="formData.description" placeholder="请输入需求描述"> -->
				<textarea v-model="formData.talentTeam" placeholder="请输入人才队伍"></textarea>
			</view>
		</view>
		<!-- <text style="font-weight: 700;">园区图片</text>
		<view class="card-fan">
			<view class="fan_left" v-show="isShow1">
				<image src="http://113.142.144.25:9301/statics/appimg/fan_new.png" mode="" @tap='touchphoto2'></image>
			</view>
			<view class="fan_right" v-show="!isShow1">
				<image :src="formData.pictureUrl" @tap='touchphoto2'></image>
			</view>
		</view> -->
		<view class="uni-form-item">
			<view v-if="submit == true" style="margin-bottom: 35rpx;background-color: #fff;">
				<button type="primary" @click="submitNeeds()">保存</button>
			</view>
			<view v-if='submit != true' style="margin-bottom: 35rpx;background-color: #fff;">
				<button type="primary" @click="intelligentMatch()">智能匹配</button>
			</view>
		</view>
		<uni-popup v-if="canlendarShow">
			<tmt-calendar defaultDate="2021-11-03" :point-list="['2022-03-20','2022-04-01','2022-04-02','2022-04-05']"
				show="canlendarShow" @changeDate="changeDate(e)"></tmt-calendar>
		</uni-popup>
	</scroll-view>
</template>

<script>
	import * as mydata from '@/api/system/dict/data.js'
	import * as kjyq from '@/api/innovate/stpkjyq.js'
	import * as match from '@/api/intelligentMatch.js'

	function getDate(type) {
		const date = new Date();

		let year = date.getFullYear();
		let month = date.getMonth() + 1;
		let day = date.getDate();

		if (type === 'start') {
			year = year - 10;
		} else if (type === 'end') {
			year = year + 10;
		}
		month = month > 9 ? month : '0' + month;
		day = day > 9 ? day : '0' + day;

		return `${year}-${month}-${day}`;
	}

	export default {
		data() {
			return {
				show: false,
				token: '',
				formData: {
					address:'',//"地址"
					agriculLevel:'',//
					agriculturalAchievement:'',//
					alreadyCirculation:'',//已流转资金
					area:'',//所属区域
					basicCondition:'',//基本条件
					benefit:'',//效益
					city:'',//
					cityLocation:'',//城市定位
					deptId:'',//
					extension:'',//"推广情况"
					financialService:'',//"金融服务"
					hasinvestedSituation:'',//"投入情况"
					inputCondition:'',//已投入资金
					marketingSituation:'',//"营销现状"
					nameofPark:'',//"园区名称"
					parkNum:'',//
					parkScale:'',//园区规模
					parkType:'',//园区类型
					parkbenefitCircumstance:'',//"园区效益
					parkexistingScale:'',//园区现有规模
					pictureUrl:'',//园区图片
					platformIntroduction:'',//"平台介绍"
					primeMoverIndustry:'',//"主导产业"
					remark:'',//
					synopsis:'',//"简介"
					talentTeam:'',//"人才队伍"
				},
				orderInfo: {
					contact:'',//
					content:'',//预约内容
					dataId:'',//
					detail:'',//
					needId:'',//需求ID
					receiverId:'',//
					subscribeTime:'',//预约时间
					telphone:'',//联系电话
					title:'',//招聘单位名字
					type:'2',//
				},
				selectJob:{},
				canlendarShow: false,
				submit: true,
				//发布级别
				levelArray: [],
				//发布级别选中项
				levelIndex: 0,
				//服务形式
				servicetypeArray: [],
				//服务形式选中项
				servicetypeIndex: 0,
				//行业领域
				industryArray: [],
				//行业领域选中项
				industryIndex: 0,
				//工作经验
				workyearArray: [],
				//工作经验选中项
				workyearIndex: 0,
				//薪资报酬
				moneyArray: [],
				//薪资报酬选中项
				moneyIndex: 0,
				//有效期
				timelimitArray: [],
				//有效期选中项
				timelimitIndex: 0,


				//截止时间选择相关
				date: getDate({
					format: true
				}),
				startDate: getDate('start'),
				endDate: getDate('end'),
				macthList: [],
				showMask: false,
				isShow1:true,
				areaArray:[],
				areaIndex:0,
			}
		},
		onLoad() {
			this.formData.company = '陕西乐尚物联'
			this.getCityList();
			this.getUser()
		},
		methods: {
			getUser() {
				const value = uni.getStorageSync("userInfo") || []
				if (value.login_user == null) {
					uni.redirectTo({
						url: '/subpages/pages/register/login_province'
					})
					uni.showToast({
						icon: 'none',
						title: '请先登录！'
					})
				} else {
					this.token = value.access_token
					this.formData.memberId = value.login_user.member.id
				}

			},
			getCityList() {
				mydata.getDicts("wanted_safe").then((response) => {
					this.levelArray = response.data;
				});
				mydata.getDicts("bus_need_type").then((response) => {
					this.typeArray = response.data;
				});
				mydata.getDicts("cms_approve_status").then((response) => {
					this.statusList = response.data;
				});
				mydata.getDicts("bus_need_level").then((response) => {
					this.emergencyArray = response.data;
				});
				mydata.getDicts("bus_need_way").then((response) => {
					this.cooperationArray = response.data;
				});
				//招聘相关字典
				mydata.getDicts("wanted_time").then((response) => {
					this.timelimitArray = response.data;
				});
				mydata.getDicts("wanted_exp").then((response) => {
					this.workyearArray = response.data;
				});
				mydata.getDicts("wanted_type").then((response) => {
					this.servicetypeArray = response.data;
				});
				mydata.getDicts("wanted_industry").then((response) => {
					this.industryArray = response.data;
				});
				mydata.getDicts("wanted_safe").then((response) => {
					this.levelArray = response.data;
				});
				mydata.getDicts("cms_money").then((response) => {
					this.moneyArray = response.data;
				});
				mydata.getArea('6103').then((res)=>{
					this.areaArray = res.data
				})
			},
			selectPics() {
				var that = this;
				uni.chooseImage({
					count: 3,
					success: (res) => {
						const files = res.tempFiles;
						let imgArr = [];
						for (let i = 0; i < files.length; i++) {
							let obj = new Object();
							obj.name = 'photo' + i;
							obj.uri = files[i].path;
							that.fileList.push(obj);
						}
					}
				})
			},
			submitNeeds() {
				this.formData.area = this.areaArray[this.areaIndex].code
				if (this.formData.nameofPark == '') {
					uni.showToast({
						icon: 'none',
						title: '园区名称不能为空！'
					})
				} else if (this.formData.parkType == '') {
					uni.showToast({
						icon: 'none',
						title: '园区类型不能为空！'
					})
				} else if (this.formData.primeMoverIndustry == '') {
					uni.showToast({
						icon: 'none',
						title: '主导产业不能为空！'
					})
				} else if (this.formData.area == '') {
					uni.showToast({
						icon: 'none',
						title: '所属区域不能为空！'
					})
				} else if (this.formData.inputCondition == '') {
					uni.showToast({
						icon: 'none',
						title: '已投入资金不能为空！'
					})
				} else if (this.formData.financialService == '') {
					uni.showToast({
						icon: 'none',
						title: '金融服务不能为空！'
					})
				} else if (this.formData.hasinvestedSituation == '') {
					uni.showToast({
						icon: 'none',
						title: '投入情况不能为空！'
					})
				} else if (this.formData.parkScale == '') {
					uni.showToast({
						icon: 'none',
						title: '园区规模不能为空！'
					})
				} else if (this.formData.marketingSituation == '') {
					uni.showToast({
						icon: 'none',
						title: '营销现状不能为空！'
					})
				} else if (this.formData.basicCondition == '') {
					uni.showToast({
						icon: 'none',
						title: '基本条件不能为空！'
					})
				} else if (this.formData.cityLocation == '') {
					uni.showToast({
						icon: 'none',
						title: '城市定位不能为空！'
					})
				} else if (this.formData.parkbenefitCircumstance == '') {
					uni.showToast({
						icon: 'none',
						title: '园区效益不能为空！'
					})
				} else if (this.formData.address == '') {
					uni.showToast({
						icon: 'none',
						title: '地址不能为空！'
					})
				} else {
					uni.showModal({
						title: '提示',
						content: '确认该申请信息无误并提交吗？',
						showCancel: true,
						cancelText: '取消',
						confirmText: '提交',
						success: (res) => {
							if (res.confirm) {
								// console.log('comfirm') //点击确定之后执行的代码
								kjyq.addStpkjyq(this.formData).then((res) => {
									this.formData = res.data
									uni.showToast({
										title: '提交成功！'
									})
									uni.navigateBack()

								})
							} else {
								console.log('cancel') //点击取消之后执行的代码
							}
						}
					})

				}
			},
			intelligentMatch() {
				var needString = 'zyfx=' + this.formData.zyfx + '&serverType=' + this.formData.serverType + '&zc=' + this
					.formData.zc +
					'&education=' + this.formData.education + '&phone=' + this.formData.phone + '&salary=' + this.formData
					.salary +
					'&personName=' + this.formData.personName + '&workYear=' + this.formData.workYear + '&delivery=' + this
					.formData.delivery +
					'&industry=' + this.formData.industry + '&memberId=' + this.formData.memberid + '&xw=' + this.formData
					.xw + '&id=' + this.formData.id
				match.rcneed(needString).then((res) => {
					this.macthList = res.data
					console.log(this.macthList)
				})
			},
			changeDate(e) {
				this.canlendarShow = false;
				var year = e.year
				var month = e.month
				if (month < 10) {
					month = "0" + month
				}
				var day = e.day
				if (day < 10) {
					day = "0" + month
				}

				this.formData.deadline = year + '-' + month + '-' + day
			},
			cooperationChange(e) {
				this.cooperationIndex = e.target.value;
				this.formData.hzfs = this.cooperationArray[this.cooperationIndex].dictValue;
			},
			typeChange(e) {
				this.typeIndex = e.target.value;
				this.formData.type = this.typeArray[this.typeIndex].dictValue;
			},
			cityChange(e) {
				this.cityIndex = e.target.value;
				this.formData.city = this.cityArray[this.cityIndex].dictValue;
			},
			bindDateChange(e) {
				this.formData.deadline = e.detail.value;
				this.date = e.detail.value;
			},
			emergencyChange(e) {
				this.emergencyIndex = e.target.value;
				this.formData.jjcd = this.typeArray[this.typeIndex].dictValue;
			},
			//招聘下拉框
			levelChange(e) {
				this.levelIndex = e.target.value;
			},
			industryChange(e) {
				this.industryIndex = e.target.value;
			},
			servicetypeChange(e) {
				this.servicetypeIndex = e.target.value;
			},
			workyearChange(e) {
				this.workyearIndex = e.target.value;
			},
			moneyChange(e) {
				this.moneyIndex = e.target.value;
			},
			areaChange(e) {
				this.areaIndex = e.target.value;
			},
			getMoney(index) {
				var money = ''
				this.moneyArray.forEach(v => {
					if (v.dictValue == index) {
						money = v.dictLabel
					}
				})
				return money;
			},
			toggle(item) {
				console.log("弹窗")
				this.selectJob = item
				// this.$refs['orderpopup'].open();
				this.showMask = true
			},
			closePopup() {
				// this.$refs['orderpopup'].close();
				this.showMask = false
			},
			submitOrder() {
				this.orderInfo.subscribeDate = this.date
				this.orderInfo.serverId = this.machineDetail.id
				this.orderInfo.serverName = this.machineDetail.insBasic.mInstruCHNName
				order.addORDER(this.orderInfo).then((res) => {
					if (res.code == '200') {
						uni.navigateTo({
							url: '/subpages/pages/my/orderList/order_list'
						})
					} else {
						uni.showToast({
							icon: 'none',
							title: '提交失败，请稍后重试！'
						})
					}
				})
			}
		}
	}
</script>

<style>
	.content {
		height: 100%;
		background-color: #e5e5e5;
		padding-bottom: 20rpx;
	}

	.content span {
		color: darkred;
	}

	.uni-form-item {
		margin: 60rpx 30rpx;
		border-radius: 50px;
	}

	.uni-form-item button {
		background-color: #016fb8;
		height: 90rpx;
		font-size: 35rpx;
		margin-top: 50rpx;
	}

	.login_from_input {
		width: 100%;
		height: auto;
		display: flex;
		flex-direction: row;
		justify-content: space-between;
		align-items: center;
		border-bottom: 1px #eee solid;
		padding: 20upx 0px;
		margin: 0px auto;
		background-color: #fff;
	}

	.login_from_name {
		width: 40%;
		margin-left: 40rpx;
		font-size: 30rpx;
	}

	.login_from_fun {
		width: 60%;
		display: flex;
		flex-direction: row;
		justify-content: flex-end;
		text-align: right;
	}

	.login_from_fun input {
		width: 100%;
		text-align: left;
		font-size: 14px;
	}

	.detail {
		background-color: #fff;
		margin-top: 25rpx;
		height: 400rpx;
	}

	.form-left {
		margin-left: 16px;
		padding: 5rpx 0;
	}

	.form-right {
		margin-top: 6px;
		margin-left: 6px;
		padding: 5px 0;
		width: 90%;
		border: 1px solid #D8D8D8;
		border-radius: 3px;
	}

	.upLoadImg {
		width: 96rpx;
		height: 96rpx;
		background-color: #FFFFFF;
		margin-top: 16rpx;
		margin-left: 6px;
	}

	.devideline {
		float: left;
		height: 0.3rpx;
		width: 100%;
		background-color: #eeeeee;
		margin-top: 25rpx;
		margin-bottom: 15rpx;
	}

	textarea {
		margin-right: 20rpx;
		height: 300rpx;
		word-wrap: break-word;
		text-align: left;
		font-size: 15px;

	}
</style>